//
//  ProjectExperienceViewController.m
//  InviteJob
//
//  Created by chirui on 2017/10/26.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "ProjectExperienceViewController.h"

@interface ProjectExperienceViewController ()<UITableViewDelegate,UITableViewDataSource>{
    
    UITableView * _tableView;
}

@end

@implementation ProjectExperienceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    TitleView(@"项目经验");
    self.view.backgroundColor =[UIColor whiteColor];
    [self creatTableView];
}

-(void)creatTableView {
    
    _tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-64) style:UITableViewStyleGrouped];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    UIView * view =[[UIView alloc]init];
    _tableView.tableFooterView = view;
    [self.view addSubview:_tableView];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 0;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 100;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    
    NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",self.projectDic[@"project_describe"]]];
    
    
    NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle1 setLineSpacing:7];
    [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [[NSString stringWithFormat:@"%@",self.projectDic[@"project_describe"]] length])];
    UILabel * workDetailsLabel = [self creatLabelFrame:CGRectMake(10, 155,WIDTH -20, 20) andTextColor:RGB(0x333333) andFount:15 andTextStr:@"" andAlignment:NSTextAlignmentLeft onView:nil];
    workDetailsLabel.attributedText = attributedString1;
    workDetailsLabel.numberOfLines = 0;
    [workDetailsLabel sizeToFit];
    
    
    return CGRectGetMaxY(workDetailsLabel.frame)+10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static  NSString * str = @"cellid";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:str];
    
    if (cell==nil) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }else {
        while ([cell.contentView.subviews lastObject]!=nil) {
            [[cell.contentView.subviews lastObject] removeFromSuperview];
        }
    }
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView * heardView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 500)];
    heardView.backgroundColor = [UIColor whiteColor];
    
    
    //    NSTextAlignmentLeft     NSTextAlignmentRight
    
    UILabel * workName = [self creatLabelFrame:CGRectMake(10, 15, 30, 20) andTextColor:[UIColor blackColor] andFount:16 andTextStr:self.projectDic[@"duty"] andAlignment:NSTextAlignmentLeft onView:heardView];
    workName.numberOfLines =1;
    [workName sizeToFit];
    
    UILabel * ageLabel = [self creatLabelFrame:CGRectMake(10, 45,WIDTH -20, 20) andTextColor:RGB(0x999999) andFount:14 andTextStr:[NSString stringWithFormat:@"%@  %@-%@",self.projectDic[@"project_name"],self.projectDic[@"b_time"],self.projectDic[@"e_time"]] andAlignment:NSTextAlignmentLeft onView:heardView];
    
    [self creatLineViewFrame:CGRectMake(0, 80, WIDTH, 10)  onView:heardView]; // 分割线
    
    UILabel * comLabel = [self creatLabelFrame:CGRectMake(10, 105,200, 20) andTextColor:[UIColor blackColor] andFount:15 andTextStr:@"项目描述" andAlignment:NSTextAlignmentLeft onView:heardView];
    
    [self creatLineViewFrame:CGRectMake(0,CGRectGetMaxY(comLabel.frame)+15, WIDTH, 0.5)  onView:heardView]; // 分割线
    
    NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",self.projectDic[@"project_describe"]]];
    
    
    NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle1 setLineSpacing:7];
    [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [[NSString stringWithFormat:@"%@",self.projectDic[@"project_describe"]] length])];
    
    UILabel * workDetailsLabel = [self creatLabelFrame:CGRectMake(10, 155,WIDTH -20, 20) andTextColor:RGB(0x333333) andFount:15 andTextStr:@"" andAlignment:NSTextAlignmentLeft onView:heardView];
    workDetailsLabel.attributedText = attributedString1;
    
    workDetailsLabel.numberOfLines = 0;
    [workDetailsLabel sizeToFit];
    
    return heardView;
}

-(UILabel *)creatLabelFrame:(CGRect)rec andTextColor:(UIColor *)col andFount:(CGFloat)fount andTextStr:(NSString *)str andAlignment:(NSTextAlignment)alignment onView:(UIView *)view{
    
    UILabel * label =[[UILabel alloc]initWithFrame:rec];
    label.font =[UIFont systemFontOfSize:fount];
    label.textColor =col;
    label.text = str;
    label.textAlignment = alignment;
    [view addSubview:label];
    return label;
}


-(void)creatLineViewFrame:(CGRect)rec onView:(UIView *)view{
    
    UIView * lineView = [[UIView alloc]initWithFrame:rec];
    lineView.backgroundColor = strColor(@"f6f6f6");
    [view addSubview:lineView];
}

@end
